using System;
using System.Collections.Generic;
using System.Linq;

namespace MimeCloud.Foundations.Extensions
{
    public static class IListExtensions
    {
        /// <summary>
        /// For each IEnumerable Action Extension.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items">The items.</param>
        /// <param name="action">The action.</param>
        public static int FindIndex<T>(this IList<T> items, Predicate<T> match) where T : class
        {
            try
            {
                return Enumerable.Range(0, items.Count()).First(x => match(items[x]));
            }
            catch (Exception)
            {
                return -1;
            }
            
        }

        public static void AddRange<T>(this IList<T> list, IEnumerable<T> items)
        {
            if (list == null) throw new ArgumentNullException("list");
            if (items == null) throw new ArgumentNullException("items");
            foreach (T item in items) list.Add(item);
        }

    }
}